package sample.clients;

import org.hibernate.HibernateException;

import sample.dao.DAO;
import sample.entity.Category;

public class CreateCategory extends DAO {

	public static void main(String[] args) {
		System.out.println("Creating category");
		CreateCategory self=new CreateCategory();
		
		try{
			
			self.create("Food");
			DAO.close();
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
	}
	
	public Category create(String title) throws Exception{
		try{
			begin();
			Category category=new Category();
			category.setTitle(title);
			getSession().save(category);
			commit();
			return category;
		}
		catch(HibernateException e){
			throw new Exception(":"+e.getMessage());
		}
	}
	
	
	
}
